{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "def is_prime(n):\n",
    "    \"\"\"判断一个数是否是素数\"\"\"\n",
    "    if n <= 1:\n",
    "        return False\n",
    "    if n == 2:\n",
    "        return True  # 2是唯一的偶数素数\n",
    "    if n % 2 == 0:\n",
    "        return False  # 其他偶数都不是素数\n",
    "    for i in range(3, int(n**0.5) + 1, 2):\n",
    "        if n % i == 0:\n",
    "            return False\n",
    "    return True\n",
    "\n",
    "def find_primes_up_to(limit):\n",
    "    \"\"\"找出小于等于给定限制的所有素数\"\"\"\n",
    "    primes = []\n",
    "    for num in range(2, limit + 1):\n",
    "        if is_prime(num):\n",
    "            primes.append(num)\n",
    "    return primes\n",
    "\n",
    "# 设置限制为1000\n",
    "limit = 1000\n",
    "# 找出并打印所有素数及其数量\n",
    "primes = find_primes_up_to(limit)\n",
    "print(f\"在1到{limit}之间共有{len(primes)}个素数。\")\n",
    "print(\"这些素数是：\")\n",
    "print(primes)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
